<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Base
{
    use Notifiable;



    public static function add($map)
    {

        $user = self::where('openid',$map['id'])->get();
        if($user->isEmpty()){
            $data['openid'] = $map['id'];
            $data['name'] = urlencode($map['nickname']);
            $data['image'] = $map['avatar'];
            $rew = self::create($data);
            if ($rew){
                //生成二维码

                return 200;
            }
        }else{
            $data['openid'] = $map['id'];
            $data['name'] = urlencode($map['nickname']);
            $data['image'] = $map['avatar'];
            $rew = self::where('openid',$map['id'])->update($data);
            if ($rew){
                return 200;
            }
        }
    }
}
